{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "otherwise-juvenile",
   "metadata": {},
   "source": [
    "作业"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adaptive-average",
   "metadata": {},
   "source": [
    "#### 随机生成6个班的考试成绩，3门考试：python、数学语文、每个班50人"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "processed-consensus",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 51,  14,  79],\n",
       "       [ 14,  98,  26],\n",
       "       [ 49,  82,   6],\n",
       "       [ 62,  78,  25],\n",
       "       [ 63,  82,  41],\n",
       "       [ 36,  23,  83],\n",
       "       [ 40,  55,  17],\n",
       "       [ 79,  68,  57],\n",
       "       [ 21,  80,  41],\n",
       "       [  2,  68,  41],\n",
       "       [  7,  19,  15],\n",
       "       [  6,  11,  13],\n",
       "       [ 43,  42,  51],\n",
       "       [  2,  78,  11],\n",
       "       [ 57,  17,  75],\n",
       "       [ 96,  87,  84],\n",
       "       [ 51,  41,  63],\n",
       "       [ 67,  62,  96],\n",
       "       [100,   5,   1],\n",
       "       [ 82,   7,  34],\n",
       "       [ 49,  44,  87],\n",
       "       [ 18,  58,  81],\n",
       "       [ 10,   0,  34],\n",
       "       [ 95,  73,  78],\n",
       "       [ 91,   4,  43],\n",
       "       [ 75,  50,   8],\n",
       "       [ 63,  48,  75],\n",
       "       [ 17,  17,   4],\n",
       "       [ 37,  65,  63],\n",
       "       [ 75,   0,  69],\n",
       "       [ 30,   3,  20],\n",
       "       [ 39,  81,  36],\n",
       "       [ 68,   7,  68],\n",
       "       [ 64,   8,  22],\n",
       "       [  4,  95,  91],\n",
       "       [ 34,  28,  54],\n",
       "       [ 65,  10,   1],\n",
       "       [ 46,  23,  22],\n",
       "       [ 32,  15,  26],\n",
       "       [  1,  42,  16],\n",
       "       [ 39,  61,  60],\n",
       "       [ 99,   1,  21],\n",
       "       [ 88,  61,  11],\n",
       "       [ 73,  91,  26],\n",
       "       [ 97,  97,  23],\n",
       "       [ 58,  77,  79],\n",
       "       [ 28,  83,   8],\n",
       "       [ 79,  46,  54],\n",
       "       [ 45,  89,   7],\n",
       "       [ 18,  53,  81]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "# 生成保留一位的小数 0-100 之间保留一位的小数\n",
    "clas1 = np.random.randint(0,101,size=(50,3))\n",
    "clas2 = np.random.randint(0,101,size=(50,3))\n",
    "clas3 = np.random.randint(0,101,size=(50,3))\n",
    "clas4 = np.random.randint(0,101,size=(50,3))\n",
    "clas5 = np.random.randint(0,101,size=(50,3))\n",
    "clas6 = np.random.randint(0,101,size=(50,3))\n",
    "clas6"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "legislative-curtis",
   "metadata": {},
   "source": [
    "#### 将6个班的考试成绩合并得到score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "turkish-copyright",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(300, 3)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将6个班成绩进行列串联axis = 0\n",
    "score = np.concatenate([clas1,clas2,clas3,clas4,clas5,clas6],axis = 0)\n",
    "score.shape #(300, 3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "incredible-harrison",
   "metadata": {},
   "source": [
    "#### 生成性别组sex水平叠加数组sex和score得到data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "speaking-logan",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[50, 88, 50,  0],\n",
       "       [54, 56,  5,  0],\n",
       "       [73,  1, 47,  0],\n",
       "       ...,\n",
       "       [76, 52, 43,  1],\n",
       "       [48, 28, 95,  1],\n",
       "       [ 7, 47, 51,  1]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sex = np.random.randint(0,2,size = (300,1)) # 注意np 中 randint 左闭右开\n",
    "sex.shape # (300, 1)\n",
    "data = np.concatenate([score,sex],axis = 1)\n",
    "data.shape # (300, 4)\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "connected-premium",
   "metadata": {},
   "source": [
    "#### 分别计算男女生的指标：最小值、最大值、平均分、中位数、标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "circular-renaissance",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0 50 50 88]\n",
      " [ 0  5 54 56]\n",
      " [ 0  1 47 73]\n",
      " ...\n",
      " [ 1 43 52 76]\n",
      " [ 1 28 48 95]\n",
      " [ 1  7 47 51]]\n"
     ]
    }
   ],
   "source": [
    "data.sort(axis = -1)\n",
    "print(data)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "likely-transcription",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 1 性别分开求解\n",
    "# 2 在括号内家条件直接分开\n",
    "b = data[:,0]\n",
    "display(b) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "portable-feelings",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0\n",
      "1 0\n",
      "2 0\n",
      "3 0\n",
      "4 0\n",
      "5 0\n",
      "6 0\n",
      "7 1\n",
      "8 1\n",
      "9 1\n",
      "10 1\n",
      "11 1\n",
      "12 1\n",
      "13 1\n",
      "14 1\n",
      "15 1\n",
      "16 1\n",
      "17 1\n",
      "18 1\n",
      "19 1\n",
      "20 1\n",
      "21 1\n",
      "22 1\n",
      "23 1\n",
      "24 1\n",
      "25 1\n",
      "26 1\n",
      "27 1\n",
      "28 1\n",
      "29 1\n",
      "30 1\n",
      "31 1\n",
      "32 1\n",
      "33 1\n",
      "34 1\n",
      "35 1\n",
      "36 1\n",
      "37 1\n",
      "38 1\n",
      "39 1\n",
      "40 1\n",
      "41 1\n",
      "42 1\n",
      "43 1\n",
      "44 1\n",
      "45 1\n",
      "46 1\n",
      "47 1\n",
      "48 1\n",
      "49 1\n",
      "50 1\n",
      "51 1\n",
      "52 1\n",
      "53 1\n",
      "54 1\n",
      "55 1\n",
      "56 1\n",
      "57 1\n",
      "58 1\n",
      "59 1\n",
      "60 1\n",
      "61 1\n",
      "62 1\n",
      "63 1\n",
      "64 1\n",
      "65 1\n",
      "66 1\n",
      "67 1\n",
      "68 1\n",
      "69 1\n",
      "70 1\n",
      "71 1\n",
      "72 1\n",
      "73 1\n",
      "74 1\n",
      "75 1\n",
      "76 1\n",
      "77 1\n",
      "78 1\n",
      "79 1\n",
      "80 1\n",
      "81 1\n",
      "82 1\n",
      "83 1\n",
      "84 1\n",
      "85 1\n",
      "86 1\n",
      "87 1\n",
      "88 1\n",
      "89 1\n",
      "90 1\n",
      "91 1\n",
      "92 1\n",
      "93 1\n",
      "94 1\n",
      "95 1\n",
      "96 1\n",
      "97 1\n",
      "98 1\n",
      "99 1\n",
      "100 1\n",
      "101 1\n",
      "102 1\n",
      "103 1\n",
      "104 1\n",
      "105 1\n",
      "106 1\n",
      "107 1\n",
      "108 1\n",
      "109 1\n",
      "110 1\n",
      "111 1\n",
      "112 1\n",
      "113 1\n",
      "114 1\n",
      "115 1\n",
      "116 1\n",
      "117 1\n",
      "118 1\n",
      "119 1\n",
      "120 1\n",
      "121 1\n",
      "122 1\n",
      "123 1\n",
      "124 1\n",
      "125 1\n",
      "126 1\n",
      "127 1\n",
      "128 1\n",
      "129 1\n",
      "130 1\n",
      "131 1\n",
      "132 1\n",
      "133 1\n",
      "134 1\n",
      "135 1\n",
      "136 1\n",
      "137 1\n",
      "138 1\n",
      "139 1\n",
      "140 1\n",
      "141 1\n",
      "142 1\n",
      "143 1\n",
      "144 1\n",
      "145 1\n",
      "146 1\n",
      "147 1\n",
      "148 1\n",
      "149 1\n",
      "150 1\n",
      "151 1\n",
      "152 1\n",
      "153 1\n",
      "154 1\n",
      "155 1\n",
      "156 1\n",
      "157 1\n",
      "158 1\n",
      "159 1\n",
      "160 1\n",
      "161 1\n",
      "162 1\n",
      "163 1\n",
      "164 1\n",
      "165 1\n",
      "166 1\n",
      "167 1\n",
      "168 1\n",
      "169 1\n",
      "170 1\n",
      "171 1\n",
      "172 1\n",
      "173 1\n",
      "174 1\n",
      "175 1\n",
      "176 1\n",
      "177 1\n",
      "178 1\n",
      "179 1\n",
      "180 1\n",
      "181 1\n",
      "182 1\n",
      "183 1\n",
      "184 1\n",
      "185 1\n",
      "186 1\n",
      "187 1\n",
      "188 1\n",
      "189 1\n",
      "190 1\n",
      "191 1\n",
      "192 1\n",
      "193 1\n",
      "194 1\n",
      "195 1\n",
      "196 1\n",
      "197 1\n",
      "198 1\n",
      "199 1\n",
      "200 1\n",
      "201 1\n",
      "202 1\n",
      "203 1\n",
      "204 1\n",
      "205 1\n",
      "206 1\n",
      "207 1\n",
      "208 1\n",
      "209 1\n",
      "210 1\n",
      "211 1\n",
      "212 1\n",
      "213 1\n",
      "214 1\n",
      "215 1\n",
      "216 1\n",
      "217 1\n",
      "218 1\n",
      "219 1\n",
      "220 1\n",
      "221 1\n",
      "222 1\n",
      "223 1\n",
      "224 1\n",
      "225 1\n",
      "226 1\n",
      "227 1\n",
      "228 1\n",
      "229 1\n",
      "230 1\n",
      "231 1\n",
      "232 1\n",
      "233 1\n",
      "234 1\n",
      "235 1\n",
      "236 1\n",
      "237 1\n",
      "238 1\n",
      "239 1\n",
      "240 1\n",
      "241 1\n",
      "242 1\n",
      "243 1\n",
      "244 1\n",
      "245 1\n",
      "246 1\n",
      "247 1\n",
      "248 1\n",
      "249 1\n",
      "250 1\n",
      "251 1\n",
      "252 1\n",
      "253 1\n",
      "254 1\n",
      "255 1\n",
      "256 1\n",
      "257 1\n",
      "258 1\n",
      "259 1\n",
      "260 1\n",
      "261 1\n",
      "262 1\n",
      "263 1\n",
      "264 1\n",
      "265 1\n",
      "266 1\n",
      "267 1\n",
      "268 1\n",
      "269 1\n",
      "270 1\n",
      "271 1\n",
      "272 1\n",
      "273 1\n",
      "274 1\n",
      "275 1\n",
      "276 1\n",
      "277 1\n",
      "278 1\n",
      "279 1\n",
      "280 1\n",
      "281 1\n",
      "282 1\n",
      "283 1\n",
      "284 1\n",
      "285 1\n",
      "286 1\n",
      "287 1\n",
      "288 1\n",
      "289 1\n",
      "290 1\n",
      "291 1\n",
      "292 1\n",
      "293 1\n",
      "294 1\n",
      "295 1\n",
      "296 1\n",
      "297 1\n",
      "298 1\n",
      "299 1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[array([[ 0, 50, 50, 88],\n",
       "        [ 0,  5, 54, 56],\n",
       "        [ 0,  1, 47, 73],\n",
       "        ...,\n",
       "        [ 1, 43, 52, 76],\n",
       "        [ 1, 28, 48, 95],\n",
       "        [ 1,  7, 47, 51]]),\n",
       " array([], shape=(300, 0), dtype=int32)]"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b.sort()\n",
    "len(b)\n",
    "for i in range( 0 , len(b)):\n",
    "     print (i, b[i])\n",
    "# 排序后 0-6性别为0 6-300性别为1 按照数量进行切割\n",
    "'''\n",
    "count1 = 0\n",
    "for i in b:\n",
    "    if i == 0:\n",
    "         count1 += 0\n",
    "print(count1)\n",
    "'''\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "jewish-performer",
   "metadata": {},
   "outputs": [],
   "source": [
    "#data0 sex=0 data1 sex=1\n",
    "data0,data1 = np.vsplit(data,indices_or_sections=[7]) # 在水平方向以索引6为分割点分成3份"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "id": "annual-sleeping",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "女生中python成绩最低为:1 数学成绩最低为:35 语文成绩最低为:38\n",
      "女生中python成绩最高为:66 数学成绩最高为:81 语文成绩最高为:94\n",
      "女生中python平均成绩为:24 数学成绩平均成绩:53 语文平均成绩为:73\n",
      "女生中python成绩中位数为:10 数学成绩中位数:50 语文成绩中位数为:80\n",
      "女生中python成绩标准差为:23 数学成绩标准差:12 语文成绩标准差为:18\n"
     ]
    }
   ],
   "source": [
    "# data0 最小值、最大值、平均分、中位数、标准差 0 性别女 成绩分别为 python、数学、语文\n",
    "# 通配符%后接受元组 tuple\n",
    "min0_1,min0_2,min0_3 = (np.min(data0,axis=0)[1:])\n",
    "print('女生中python成绩最低为:%d 数学成绩最低为:%d 语文成绩最低为:%d' % (min0_1,min0_2,min0_3))\n",
    "max0 = tuple(np.max(data0,axis=0)[1:])\n",
    "print('女生中python成绩最高为:%d 数学成绩最高为:%d 语文成绩最高为:%d' % (max0))\n",
    "mean0 = tuple(np.mean(data0,axis=0)[1:])\n",
    "print('女生中python平均成绩为:%d 数学成绩平均成绩:%d 语文平均成绩为:%d' % (mean0))\n",
    "median0 = tuple(np.median(data0,axis=0)[1:])\n",
    "print('女生中python成绩中位数为:%d 数学成绩中位数:%d 语文成绩中位数为:%d' % (median0))\n",
    "print('女生中python成绩标准差为:%d 数学成绩标准差:%d 语文成绩标准差为:%d' % tuple(np.std(data0,axis=0)[1:]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "suspended-turner",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "男生中python成绩最低为:1 数学成绩最低为:5 语文成绩最低为:16\n",
      "男生中python成绩最高为:84 数学成绩最高为:96 语文成绩最高为:99\n",
      "男生中python平均成绩为:22 数学成绩平均成绩:48 语文平均成绩为:74\n",
      "男生中python成绩中位数为:20 数学成绩中位数:49 语文成绩中位数为:77\n",
      "男生中python成绩标准差为:17 数学成绩标准差:21 语文成绩标准差为:18\n"
     ]
    }
   ],
   "source": [
    "# data1 最小值、最大值、平均分、中位数、标准差 0 性别女 成绩分别为 python、数学、语文\n",
    "# 通配符%后接受元组 tuple\n",
    "min1_1,min1_2,min1_3 = (np.min(data1,axis=0)[1:])\n",
    "print('男生中python成绩最低为:%d 数学成绩最低为:%d 语文成绩最低为:%d' % (min1_1,min1_2,min1_3))\n",
    "max1 = tuple(np.max(data1,axis=0)[1:])\n",
    "print('男生中python成绩最高为:%d 数学成绩最高为:%d 语文成绩最高为:%d' % (max1))\n",
    "mean1 = tuple(np.mean(data1,axis=0)[1:])\n",
    "print('男生中python平均成绩为:%d 数学成绩平均成绩:%d 语文平均成绩为:%d' % (mean1))\n",
    "median1 = tuple(np.median(data1,axis=0)[1:])\n",
    "print('男生中python成绩中位数为:%d 数学成绩中位数:%d 语文成绩中位数为:%d' % (median1))\n",
    "print('男生中python成绩标准差为:%d 数学成绩标准差:%d 语文成绩标准差为:%d' % tuple(np.std(data1,axis=0)[1:]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "id": "vertical-samoa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\Administrator\\\\拉钩数据分析\\\\3-numpy'"
      ]
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%pwd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "disturbed-toddler",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
